package com.haois.mp.wechat.config;


import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaUserServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信小程序服务配置
 */
@Configuration
public class MaConfig {


	@Value("${defined.mini.app-id}")
	private String appId;
	@Value("${defined.mini.app-secret}")
	private String appSecret;
	@Value("${defined.upload-tmp-url}")
	private String tmpDirFilePath;

	/**
	 * 微信客户端配置存储
	 * @return
	 */
	@Bean
	public WxMaConfig wxMaConfig(){
		WxMaInMemoryConfig wxMaInMemoryConfig = new WxMaInMemoryConfig();
		wxMaInMemoryConfig.setAppid(appId);
		wxMaInMemoryConfig.setSecret(appSecret);
		return wxMaInMemoryConfig;
	}

	@Bean
	public WxMaService wxMaService(){
		WxMaService wxMaService = new WxMaServiceImpl();
		wxMaService.setWxMaConfig(wxMaConfig());
		return wxMaService;
	}
	@Bean
	public WxMaUserService wxMaUserService(){
		WxMaUserService wxMaUserService = new WxMaUserServiceImpl(wxMaService());
		return wxMaUserService;
	}


}
